home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_04
/
zeke2
/
native.doc
< prev
next >
Wrap
Text File
|
1995-03-06
|
9KB
|
175 lines
Class implementation under Windows/NT and Windows/3.1:
======================================================
As a prerequisite, the Windows environment requires that the application
has a function WinMain. In this function the library initializes its
global variables, then creates argc, and argv from the command line.
Finally it calls main() (which is redefined as ApplicationMain).
The GUI_APPLICATION class:
The constructor of the GUI_APPLICATION object first opens the log file. It
registers one window procedure, GuiWindowProc() for all of its windows
using RegisterClass(), then queries the screen dimensions and the default
font height. The MainLoop() function implements the main Windows
message loop through GetMessage(), TranslateMessage, and DispatchMessage().
The Terminate() function posts a quit message which in turn breaks the
message loop.
The constructor of the GUI_WINDOW object creates a standard window using
the CreateWindow() function and the earlier registered window class, and
adds itself to the window list of the GUI_APPLICATION object.
The main window procedure:
Whenever a window needs to be repainted Windows delivers a WM_PAINT
message to the window's window procedure, GuiWindowProc(). GuiWindowProc,
in turn, calls the Paint() function of the GUI_WINDOW object which goes
through the list of its children and calls the Paint() function for the
ones which are not implemented as native windows. (Namely for the GUI_LINE
and for the GUI_ELLIPSE objects.)
Whenever the window is resized, Windows delivers a WM_PAINT and a WM_SIZE
message. The WM_SIZE message is processed by calling the SizeChildren()
function which recalculates the sizes of all native-window children.
Whenever the user activates a button or an entry field is losing focus,
Windows sends a WM_COMMAND message to the window procedure.
GuiWindowProc() finds the parent window for the object then the object
itself and calls its Activate() function.
Graphical objects:
Windows expects the application to redraw the graphical objects
GUI_LINE and GUI_ELLIPSE. Therefore, both of these classes have a
non-trivial Paint() function which repaints the object. Their destructors
invalidate the bounding rectangle of the object, so the next repaint of the
parent window will erase them.
Non-graphical objects:
The implementation of the non-graphical, native-window using classes
(GUI_TEXT, GUI_BUTTON, and GUI_ENTRY) are pretty straightforward. The only
interesting point is that the library wants to catch all of the mouse
events for buttons. In order to do so, it needs to override the built in
window procedure for buttons. Windows uses the term "subclassing the
window" for this. Hence, in the constructor of GUI_BUTTON it subclasses
the window by providing its own window procedure, GuiButtonProc(). This
new window procedure handles all of the messages what the library is
interested in. All other messages are sent to the original button window
procedure, therefore the default behavior of the window is not changed.
Class implementation under OS/2 2.1:
====================================
The implementation is extremely similar to the Windows version.
The GUI_APPLICATION class:
The constructor of the GUI_APPLICATION object first opens the log file,
uses the WinInitialize() function to initialize the application, then
creates a message queue with the default queue-length using
WinCreateMsgQueue(). It registers one window procedure, GuiWindowProc()
for all of its windows using WinRegisterClass(). The MainLoop() function
implements the main PM message loop through WinGetMsg() and
WinDispatchMsg(). The Terminate() function posts a WM_CLOSE message to the
first window of the application which in turn generates a WM_QUIT message,
which breaks the message loop.
The constructor of the GUI_WINDOW object creates a standard window using
the WinCreateStdWindow() function and the earlier registered window class,
and adds itself to the window list of the GUI_APPLICATION object.
The main window procedure:
Whenever the window needs to be repainted PM delivers a WM_PAINT message
to the window's window procedure, GuiWindowProc(). GuiWindowProc, in turn,
calls the Paint() function of the GUI_WINDOW object which goes through the
list of its children and calls the Paint() function for the ones which are
not implemented as native windows. (Namely for the GUI_LINE and
the GUI_ELLIPSE objects.)
Whenever the window is resized, PM delivers a WM_PAINT and a WM_SIZE
message. The WM_SIZE message is processed by calling the SizeChildren()
function which recalculates the sizes of all native-window children.
Whenever the user activates a button, PM sends a WM_COMMAND message to the
window procedure. GuiWindowProc() finds the parent window for the object
then the object itself and calls its Activate() function.
Similarly, whenever an entry field loses focus, PM sends a WM_CONTROL
message to the window procedure. As above, the entry field is found, then
its Activate() function is called.
About graphical and non-graphical objects, see the Windows section since
their handling is identical.
Class implementation under Motif 1.2 and X11R5:
===============================================
The GUI_APPLICATION class:
The constructor of the GUI_APPLICATION object first opens the log file,
uses the XtAppInitialize() function to initialize the application and
create an application shell, picks up the default font (can be set even
through the command line), then allocates the VGA colors. The MainLoop()
function implements the main X message loop through XtAppNextEvent() and
XtDispatchEvent(). The Terminate() function sets the dontQuit variable to
0 which breaks the main message loop. To guarantee that there is at least
one message in the message loop after the Terminate() functions returns,
this function also sets up a timer which in turn generates an X message.
The constructor of the GUI_WINDOW object either creates a new toplevel
shell or reuses the original shell widget as a frame, then creates a
drawing are widget as its child. It registers two callback functions,
ResizeCallback() and ExposeCallback(), to handle the resizing and
repainting of the window. Finally, it allocates a graphics context for the
window and adds itself to the window list of the GUI_APPLICATION object.
Whenever any part of the window needs to be repainted X calls the
ExposeCallback() function. This function collects the refreshable
rectangles, then, in turn, calls the Paint() function of the GUI_WINDOW
object which goes through the list of its children and calls the Paint()
function for the ones which are not implemented as native windows. (Namely
for the GUI_LINE and the GUI_ELLIPSE objects.)
Whenever the window is resized, X calls the ResizeCallback() function. This
function clears the entire window, then calls the SizeChildren() function
which recalculates the sizes of all native-window children.
Whenever the user activates a button, X calls the functions registered
with the button for the activate action. In this case
ButtonActivateCallback(). This function has an optional parameter where
the library passes the object pointer. Using this pointer as a GUI_BUTTON
pointer, this function calls its Activate() function.
Similarly, whenever an entry field loses focus X calls the function
which is registered for this action (EntryActivateCallback().)
Graphical objects:
X expects the application to redraw the graphical objects GUI_LINE and
GUI_ELLIPSE. Therefore, both of these classes have a non-trivial Paint()
function which repaints the object. Their destructors clears the bounding
rectangle of the object, so the next repaint of the parent window will
erase them.
Non-graphical objects:
The implementation of the non-graphical, native-window using classes
(GUI_TEXT, GUI_BUTTON, and GUI_ENTRY) are pretty straightforward. The only
interesting point is that the library wants to catch all of the mouse
events for buttons. In order to do so, it needs to register an event
handler, ButtonEventHandler(), to catch all of the mouse events. Since the
library wants to be able to provide left and right double click calls